package com.itshare.video.mapper;

import com.itshare.video.pojo.po.User;
import com.itshare.video.pojo.po.UserExample;
import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.session.RowBounds;

public interface UserMapper {
    long countByExample(UserExample example);

    int deleteByExample(UserExample example);

    @Delete({
        "delete from t_user",
        "where user_id = #{userId,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long userId);

    @Insert({
        "insert into t_user (REVISION, CREATED_BY, ",
        "CREATED_TIME, UPDATED_BY, ",
        "UPDATED_TIME, user_name, ",
        "email, password, ",
        "nickname, avatar, ",
        "role_id, delete_status, ",
        "user_introduce, follower_count, ",
        "fans_count, like_count, ",
        "read_count, play_count)",
        "values (#{revision,jdbcType=INTEGER}, #{createdBy,jdbcType=VARCHAR}, ",
        "#{createdTime,jdbcType=TIMESTAMP}, #{updatedBy,jdbcType=VARCHAR}, ",
        "#{updatedTime,jdbcType=TIMESTAMP}, #{userName,jdbcType=VARCHAR}, ",
        "#{email,jdbcType=VARCHAR}, #{password,jdbcType=VARCHAR}, ",
        "#{nickname,jdbcType=VARCHAR}, #{avatar,jdbcType=VARCHAR}, ",
        "#{roleId,jdbcType=INTEGER}, #{deleteStatus,jdbcType=INTEGER}, ",
        "#{userIntroduce,jdbcType=VARCHAR}, #{followerCount,jdbcType=INTEGER}, ",
        "#{fansCount,jdbcType=INTEGER}, #{likeCount,jdbcType=INTEGER}, ",
        "#{readCount,jdbcType=INTEGER}, #{playCount,jdbcType=INTEGER})"
    })
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="userId", before=false, resultType=Long.class)
    int insert(User record);

    int insertSelective(User record);

    List<User> selectByExampleWithRowbounds(UserExample example, RowBounds rowBounds);

    List<User> selectByExample(UserExample example);

    @Select({
        "select",
        "user_id, REVISION, CREATED_BY, CREATED_TIME, UPDATED_BY, UPDATED_TIME, user_name, ",
        "email, password, nickname, avatar, role_id, delete_status, user_introduce, follower_count, ",
        "fans_count, like_count, read_count, play_count",
        "from t_user",
        "where user_id = #{userId,jdbcType=BIGINT}"
    })
    @ResultMap("com.itshare.video.mapper.UserMapper.BaseResultMap")
    User selectByPrimaryKey(Long userId);

    int updateByExampleSelective(@Param("record") User record, @Param("example") UserExample example);

    int updateByExample(@Param("record") User record, @Param("example") UserExample example);

    int updateByPrimaryKeySelective(User record);

    @Update({
        "update t_user",
        "set REVISION = #{revision,jdbcType=INTEGER},",
          "CREATED_BY = #{createdBy,jdbcType=VARCHAR},",
          "CREATED_TIME = #{createdTime,jdbcType=TIMESTAMP},",
          "UPDATED_BY = #{updatedBy,jdbcType=VARCHAR},",
          "UPDATED_TIME = #{updatedTime,jdbcType=TIMESTAMP},",
          "user_name = #{userName,jdbcType=VARCHAR},",
          "email = #{email,jdbcType=VARCHAR},",
          "password = #{password,jdbcType=VARCHAR},",
          "nickname = #{nickname,jdbcType=VARCHAR},",
          "avatar = #{avatar,jdbcType=VARCHAR},",
          "role_id = #{roleId,jdbcType=INTEGER},",
          "delete_status = #{deleteStatus,jdbcType=INTEGER},",
          "user_introduce = #{userIntroduce,jdbcType=VARCHAR},",
          "follower_count = #{followerCount,jdbcType=INTEGER},",
          "fans_count = #{fansCount,jdbcType=INTEGER},",
          "like_count = #{likeCount,jdbcType=INTEGER},",
          "read_count = #{readCount,jdbcType=INTEGER},",
          "play_count = #{playCount,jdbcType=INTEGER}",
        "where user_id = #{userId,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(User record);
}